package c.j.a.d.b.j;

import c.j.a.d.b.e.b;
import c.j.a.d.b.i.e;
import c.j.a.d.b.i.h;
import c.j.a.d.b.i.i;
import f.a0;
import f.c0;
import f.d;
import f.v;
import f.x;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.zip.GZIPInputStream;

/* compiled from: DefaultDownloadHttpService */
public class l implements i {

    /* compiled from: DefaultDownloadHttpService */
    public class a implements e {
        public final /* synthetic */ InputStream a;
        public final /* synthetic */ a0 b;
        public final /* synthetic */ d c;
        public final /* synthetic */ c0 d;

        public a(l lVar, InputStream inputStream, a0 a0Var, d dVar, c0 c0Var) {
            this.a = inputStream;
            this.b = a0Var;
            this.c = dVar;
            this.d = c0Var;
        }

        public InputStream a() throws IOException {
            return this.a;
        }

        public int b() throws IOException {
            return this.b.c;
        }

        public void c() {
            d dVar = this.c;
            if (dVar != null && !((x) dVar).b.d) {
                ((x) this.c).a();
            }
        }

        public void d() {
            try {
                c0 c0Var = this.d;
                if (c0Var != null) {
                    c0Var.close();
                }
                d dVar = this.c;
                if (dVar != null && !((x) dVar).b.d) {
                    ((x) this.c).a();
                }
            } catch (Throwable unused) {
            }
        }

        public String a(String str) {
            str = this.b.f.c(str);
            return str != null ? str : null;
        }
    }

    public h a(int i, String str, List<com.ss.android.socialbase.downloader.g.e> list) throws IOException {
        v v = b.v();
        if (v != null) {
            f.y.a aVar = new f.y.a();
            aVar.e(str);
            if (list != null && list.size() > 0) {
                for (com.ss.android.socialbase.downloader.g.e eVar : list) {
                    aVar.a(eVar.a, c.j.a.d.b.n.a.U(eVar.b));
                }
            }
            d a = v.a(aVar.b());
            a0 b = ((x) a).b();
            c0 c0Var = b.g;
            String str2 = null;
            if (c0Var == null) {
                return null;
            }
            InputStream p0 = c0Var.q().p0();
            String c = b.f.c("Content-Encoding");
            if (c != null) {
                str2 = c;
            }
            InputStream gZIPInputStream = (str2 == null || !"gzip".equalsIgnoreCase(str2) || (p0 instanceof GZIPInputStream)) ? p0 : new GZIPInputStream(p0);
            return new a(this, gZIPInputStream, b, a, c0Var);
        }
        throw new IOException("can't get httpClient");
    }
}
